import 'package:flutter/material.dart';
import 'package:flutter_frame/app/core/utils/user_manager.dart';
import 'package:flutter_frame/router/app_pages.dart';
import 'package:get/get_navigation/src/routes/route_middleware.dart';


/// 认证中间件, 未登录时重定向到登录页
class AppAuthMiddleWare extends GetMiddleware {
  @override
  RouteSettings? redirect(String? route) {
    if (!UserManager.isLoggedIn) {
      // AppToast.showErrorToastWarning('请先登录');
      /// 重定向到登录页面去
      /// 这里可以把登录前的页面route传给登录页, 在登录成功后再跳转.
      return const RouteSettings(name: AppRoutes.authLogin);
    } else {
      return super.redirect(route);
    }
  }
}
